package com.revenant.driver.ui.activity;

import android.os.Bundle;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.revenant.driver.R;
import com.revenant.driver.adapter.FaPiaoDetailItemAdapter;
import com.revenant.driver.base.BaseActivity;
import com.revenant.driver.bean.ShipperBean.FaPiaoDetailBean;
import com.revenant.driver.bean.ShipperBean.FaPiaoDetailItemBean;
import com.revenant.driver.utils.GsonUtil;
import com.revenant.driver.utils.SPUtils;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.revenant.driver.utils.Constants.Fa_Piao_History_Detail;

public class FaPiaoDetailActivity extends BaseActivity {
    @BindView(R.id.recyclerview)
    RecyclerView recyclerview;
    FaPiaoDetailItemAdapter mFaPiaoDetailItemAdapter;

    List<FaPiaoDetailItemBean> mFaPiaoDetailItemBeans;

    private int fapiaoid = 0;
    List<String> mListtype  = Arrays.asList(
            "发票抬头",
            "税号",
            "电话",
            "公司地址",
            "开户银行",
            "银行账号",
            "备注",
            "收件人",
            "收件人电话",
            "邮寄地址"
    );
    List<String> mListtitle = new ArrayList<>();

    @Override
    public int getContentViewResId() {
        return R.layout.activity_fapiaodetail;
    }

    @Override
    public void initView() {
        Bundle bundle = getIntent().getExtras();
        fapiaoid = bundle.getInt("fapiaodetailid");
        mFaPiaoDetailItemAdapter = new FaPiaoDetailItemAdapter();
        recyclerview.setLayoutManager(new LinearLayoutManager(this));
        recyclerview.setAdapter(mFaPiaoDetailItemAdapter);
        mFaPiaoDetailItemBeans = new ArrayList<>();

    }

    @Override
    public void leftbarclick() {
        super.leftbarclick();
        finish();
    }

    @Override
    public void initData() {
        look();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    private void look() {
        OkGo.<String>get(Fa_Piao_History_Detail)

                .params("id", fapiaoid)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        FaPiaoDetailBean detailBen = GsonUtil.parseJsonWithGson(response.body(), FaPiaoDetailBean.class);
                        if (detailBen.getCode().equals("0")) {
                            mListtitle.add(detailBen.getData().getTitleName());
                            mListtitle.add(detailBen.getData().getTaxNumber());
                            mListtitle.add(detailBen.getData().getPhone());
                            mListtitle.add(detailBen.getData().getCompanyAddress());
                            mListtitle.add(detailBen.getData().getBank());
                            mListtitle.add(detailBen.getData().getBankAccount());
                            mListtitle.add(detailBen.getData().getRemark());
                            mListtitle.add(detailBen.getData().getAddressee());
                            mListtitle.add(detailBen.getData().getTelePhone());
                            mListtitle.add(detailBen.getData().getAddress());
                            for (int i = 0; i < mListtitle.size(); i++) {
                                FaPiaoDetailItemBean detailBean = new FaPiaoDetailItemBean();
                                detailBean.setTitle(mListtitle.get(i));
                                detailBean.setTitletype(mListtype.get(i));
                                mFaPiaoDetailItemBeans.add(detailBean);
                            }
                            mFaPiaoDetailItemAdapter.setNewData(mFaPiaoDetailItemBeans);


                        }

                    }
                });
    }
}
